<?php 

	class database
	{
		var $user_name = "root";
		var $password = "";
		var $database = "radio";
		var $server = "localhost";
		var $db_handle = null;
		var $db_found = null;
		
		function connect_database()
		{
			$this->db_handle = mysql_connect($this->server, $this->user_name, $this->password);
			return $this->db_handle;
		}
		
		function select_database()
		{
			$this->db_found = mysql_select_db($this->database, $this->db_handle);
			return $this->db_found;
		}
		
		function schedule_tune($email)
		{
	
		}
		
		function validate_email($email)
		{
			$db_handle = $this->connect_database();
			$db_found = $this->select_database();
			
			if ($db_found) {
			
				$SQL = "SELECT * FROM scheduled_tunes WHERE email='$email'";
				$result = mysql_query($SQL);
				$result_array = array();
				
				while($r = mysql_fetch_assoc($result))
				{
					$result_array[] = $r;
				}
				
				if($result_array != NULL)
				{
					$_SESSION['email_status'] = "You have been here before!";
					$_SESSION['email'] = $email;
					$_SESSION['results'] = $result_array;
					header( 'Location: index.php' );
				} else {
					$_SESSION['email'] = $email;
					$_SESSION['email_status'] = "You have NOT been here before! Therefor you do not have any scheduled TUNES coming up! Rest assured you can still do some stuff below!";
					header( 'Location: index.php' );
				}
					
				mysql_close($db_handle);
			
			} else {
				print "Database NOT Found.";
				mysql_close($db_handle);
			}
		}
		
	}

?>